/**
 * The file for the Ship class.
 */

package edu.gatech.information;

/**
 * This is the ship class, it holds information about the speed and cargo size of the ship
 * @author Hippie Mind Control
 * @version 1.0
 */

public class Ship {
	
	/** The cargo */
	private int[] cargo;
	
	/** The cargo bay size */
	private int cargoBaySize;
	
	/** The ship's speed */
	private int shipSpeed;
	
	/** The current and max fuel levels */
	private int fuelLevel, currentFuel;
	
	/** The type of ship */
	private ShipType shipType;
	
	/**
	 * Creates a new ship and sets the ship type, which sets the cargo bay size and the ship speed
	 */
	public Ship() {
		shipType = ShipType.GNAT;
		cargo = new int[11];
		for(int i = 0; i < 11; i++) {
			cargo[i] = 0;
		}
		cargoBaySize = 3;
		shipSpeed = 5;
		fuelLevel = 15;
		currentFuel = fuelLevel;
	}
	
	/**
	 * Gets the cargo int array associated with the ship
	 * @return cargo
	 */
	public int[] getCargo() {
		return cargo;
	}
	
	/**
	 * Sets the cargo of the ship
	 * @param cargo
	 */
	public void setCargo(int[] cargo) {
		System.arraycopy(cargo, 0, this.cargo, 0, cargo.length);
	}
	
	/**
	 * Determines the total amount of cargo in the ship
	 * @return sum
	 */
	public int totalCargo() {
		int sum = 0;
		for(int i = 0; i < 10; i++) {
			sum += cargo[i];
		}
		return sum;
	}
	
	/**
	 * Checks to see if the cargo bay is full
	 * @return true or false
	 */
	public boolean canAddCargo() {
		return(totalCargo() != cargoBaySize);
	}
	
	/**
	 * Adds cargo to the int array of the cargo
	 * @param index
	 */
	public void addCargoTo(int index) {
		cargo[index]++;
	}
	
	/**
	 * Removes cargo from the int array of the cargo
	 * @param index
	 */
	public void removeCargoFrom(int index) {
		cargo[index]--;
	}
	
	/**
	 * Enum list of the different ship types
	 *
	 */
	public enum ShipType {
		GNAT,
		FIREFLY,
		MOSQUITO,
		BUMBLEBEE,
		BEETLE,
		HORNET,
		GRASSHOPPER,
		TERMITE,
		WASP,
	}
	
	/**
	 * Sets the ship type of the player and updates the cargo bay size and ship speed appropriately
	 * @param shipType
	 */
	public void setShipType(ShipType shipType) {
		this.shipType = shipType;
		switch(shipType) {
		case GNAT:
			setCargoBaySize(3);
			setShipSpeed(5);
			setFuelLevel(15);
			break;
		case FIREFLY:
			setCargoBaySize(4);
			setShipSpeed(8);
			setFuelLevel(20);
			break;
		case MOSQUITO:
			setCargoBaySize(5);
			setShipSpeed(10);
			setFuelLevel(22);
			break;
		case BUMBLEBEE:
			setCargoBaySize(8);
			setShipSpeed(10);
			setFuelLevel(25);
			break;
		case BEETLE:
			setCargoBaySize(10);
			setShipSpeed(10);
			setFuelLevel(27);
			break;
		case HORNET:
			setCargoBaySize(10);
			setShipSpeed(15);
			setFuelLevel(30);
			break;
		case GRASSHOPPER:
			setCargoBaySize(12);
			setShipSpeed(16);
			setFuelLevel(32);
			break;
		case TERMITE:
			setCargoBaySize(15);
			setShipSpeed(18);
			setFuelLevel(35);
			break;
		case WASP:
			setCargoBaySize(15);
			setShipSpeed(18);
			setFuelLevel(35);
			break;
		}
	}
	
	/**
	 * Get the fuel amount left in the ship
	 * @return fuelLevel
	 */
	public int getFuelLevel() {
		return fuelLevel;
	}
	
	/**
	 * Set the fuel amount in the ship
	 * @param fuelLevel
	 */
	public void setFuelLevel(int fuelLevel) {
		this.fuelLevel = fuelLevel;
	}
	
	/**
	 * Gets the ship type
	 * @return shipType
	 */
	public ShipType getShipType() {
		return shipType;
	}
	
	/**
	 * Gets cargo bay size of the ship
	 * @return cargoBaySize
	 */
	public int getCargoBaySize() {
		return cargoBaySize;
	}
	
	/**
	 * Sets the cargo bay size of the ship
	 * @param cargoBaySize
	 */
	public void setCargoBaySize(int cargoBaySize) {
		this.cargoBaySize = cargoBaySize;
	}
	
	/**
	 * Gets the speed the ship travels at
	 * @return shipSpeed
	 */
	public int getShipSpeed() {
		return shipSpeed;
	}
	
	/**
	 * Sets the ship speed
	 * @param shipSpeed
	 */
	public void setShipSpeed(int shipSpeed) {
		this.shipSpeed = shipSpeed;
	}
	
	/**
	 * Checks if fuel is full.
	 * @return Whether or not fuel is full
	 */
	public boolean canAddFuel() {
		return (currentFuel < fuelLevel);
	}
	
	/**
	 * Gets the amount of fuel currently on the ship
	 * @return currentFuel
	 */
	public int getCurrentFuel() {
		return currentFuel;
	}
	
	/**
	 * Sets the amount of fuel that is currently on the ship
	 * @param currentFuel
	 */
	public void setCurrentFuel(int currentFuel) {
		this.currentFuel = currentFuel;
	}
	
	/**
	 * This is used to save the game to a text file
	 * @return saveString
	 */
	public String saveString(){
		String saveString = "";
		saveString += cargoBaySize + "," + shipSpeed + "," + fuelLevel + "," + currentFuel + ",";
		for(int i = 0; i < cargo.length; i++){
			saveString += cargo[i] + ",";
			//System.out.print(cargo[i] + " ");
		}
		return saveString;
	}
	
	/**
	 * Returns a string version of the ship.
	 * @return The ship in string form.
	 */
	public String toString() {
		return "Ship";
	}
}
